
from typing import Tuple
from PIL import Image
from marker.schema import BlockTypes
from marker.schema.blocks import Block
from typing import Annotated, List
from ..processors import BaseOptProcessor
from ..vlm.vlm_analyze import VlmAnalyzer
from ..config import settings


class OptFormProcessor(BaseOptProcessor):
    block_types: Annotated[
        Tuple[BlockTypes],
        "The block types to process.",
    ] = (BlockTypes.Form, )
    vlm = VlmAnalyzer(settings.VLM_SERVER_URL)
    prompts = 'Here is a form, Form Parsing:'

    def process_rewriting(self,
            doc_blocks: List[Block],
            block_images: List[Image.Image]
    ):
        page_markdowns = self.vlm.batch_analyze(block_images, self.prompts)
        block_datas = []
        for block, markdown in zip(doc_blocks, page_markdowns):
            block_datas.append({
                'id': str(block.id),
                'html': markdown
            })
        return block_datas